package com.ikingtech.framework.sdk.oss.api;

import com.ikingtech.framework.sdk.base.model.BatchParam;
import com.ikingtech.framework.sdk.core.response.R;
import com.ikingtech.framework.sdk.oss.model.OssFileDTO;
import com.ikingtech.framework.sdk.oss.model.OssFileQueryParamDTO;
import com.ikingtech.framework.sdk.web.annotation.GetRequest;
import com.ikingtech.framework.sdk.web.annotation.PostRequest;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * @author tie yan
 */
public interface OssApi {

    @PostRequest(order = 1, value = "/file/update", summary = "更新文件信息", description = "更新文件信息")
    R<OssFileDTO> update(@Parameter(name = "file", description = "文件信息")
                         @RequestBody OssFileDTO file);

    @PostRequest(order = 1, value = "/file/list/page", summary = "分页查询文件", description = "上传文件")
    R<List<OssFileDTO>> page(@Parameter(name = "queryParam", description = "查询条件")
                             @RequestBody OssFileQueryParamDTO queryParam);

    @PostRequest(order = 1, value = "/file/list/all", summary = "查询文件(全量)", description = "上传文件")
    R<List<OssFileDTO>> all();

    @PostRequest(order = 1, value = "/file/list/ids", summary = "查询文件(多文件编号)", description = "查询文件(多文件编号)")
    R<List<OssFileDTO>> listByIds(@Parameter(name = "queryParam", description = "查询条件")
                                  @RequestBody BatchParam<String> ids);

    @PostRequest(order = 1, value = "/upload", summary = "上传文件", description = "上传文件")
    R<OssFileDTO> upload(@Parameter(name = "file", description = "文件对象")
                         @RequestPart("file") MultipartFile file,
                         @Parameter(name = "dir", description = "文件目录")
                         @RequestParam(value = "dir", required = false) String dir);

    @PostRequest(order = 2, value = "/upload/byte", summary = "上传文件(Byte数组)", description = "上传文件(Byte数组)")
    R<OssFileDTO> uploadByte(@Parameter(name = "fileName", description = "文件名")
                             @RequestParam(value = "fileName") String fileName,
                             @Parameter(name = "dir", description = "文件目录")
                             @RequestParam(value = "dir", required = false) String dir,
                             @Parameter(name = "fileByte", description = "文件Byte数组")
                             @RequestBody byte[] fileByte);

    @GetRequest(order = 3, value = "/download", summary = "下载文件", description = "下载文件，由平台的文件服务先下载文件，再将文件流返回。")
    void download(@Parameter(name = "fileUrl", description = "文件相对路径")
                  @RequestParam(value = "fileUrl") String fileUrl,
                  @Parameter(name = "fileUrl", description = "文件相对路径")
                  @RequestParam(value = "preview", required = false) Boolean preview,
                  HttpServletResponse response);

    @GetRequest(order = 3, value = "/download/byte", summary = "下载文件(Byte数组)", description = "下载文件(Byte数组)。")
    R<byte[]> downloadByte(@Parameter(name = "fileUrl", description = "文件相对路径")
                           @RequestParam("fileUrl") String fileUrl);

    @PostRequest(order = 4, value = "/delete", summary = "删除文件", description = "根据文件相对路径删除一个文件，无论指定的文件相对路径是否存在都会返回执行成功。")
    R<Object> delete(@Parameter(name = "fileUrl", description = "文件相对路径")
                     @RequestParam("fileUrl") String fileUrl);
}
